{smcl}
{txt}{sf}{ul off}{.-}
      name:  {res}<unnamed>
       {txt}log:  {res}C:\Users\hilar\Box\lights_2022\replication package\code\read_ascii_cru.smcl
  {txt}log type:  {res}smcl
 {txt}opened on:  {res}13 Dec 2025, 11:42:58
{txt}
{com}. timer on 1
{txt}
{com}. 
. 
. **# Precipitation and temperature in loop by variable and decade
. 
. foreach v in tmp pre {c -(}
{txt}  2{com}. 
. foreach yr in 1991 2001 2011 {c -(}
{txt}  3{com}. 
. local end=`yr'+9
{txt}  4{com}. 
. infile `v'1-`v'720 using "../data/cru/cru_ts4.08.`yr'.`end'.`v'.dat", clear
{txt}  5{com}. 
. * replace missing values with true missing
. quietly: mvdecode `v'1-`v'720, mv(-999)
{txt}  6{com}. 
. 
. gen int y=360-mod((_n-1),360)
{txt}  7{com}. gen int year=int((_n-1)/4320)
{txt}  8{com}. gen int month=int((_n-1)/360)-year*12+1
{txt}  9{com}. replace year=year+`yr'
{txt} 10{com}. 
. label var y "Latitude row #"
{txt} 11{com}. 
. 
. *create annual averages
. collapse `v'1-`v'720, by(year y)
{txt} 12{com}. 
. tempfile `v'`yr'
{txt} 13{com}. save ``v'`yr''
{txt} 14{com}. {c )-}
{txt} 15{com}. 
. append using ``v'1991' ``v'2001'
{txt} 16{com}. 
. *drop observations outside the range we use:
. drop if y<31 | y>300
{txt} 17{com}. 
. *renumber x to account for dropped polar rows
. 
. replace y=y-30
{txt} 18{com}. *create one obs per (x,y) pair per year
. reshape long `v', i(y year) j(x) favor(speed)
{txt} 19{com}. 
. *should be divided by 10 (surprise!)  See: https://crudata.uea.ac.uk/cru/data/hrg/#info
. replace `v'=`v'/10
{txt} 20{com}. 
. 
. *create deviations based on all years back to 1991 before dropping extraneous years
. bysort y x: egen av`v'=mean(`v')
{txt} 21{com}. gen dev_`v'=`v'-av`v'
{txt} 22{com}. label var dev_`v' "Temperature anomaly" 
{txt} 23{com}. label var `v' "Annual average temp (C)"
{txt} 24{com}. 
. 
. if "`v'" == "pre" {c -(}
{txt} 25{com}. rename  pre precip
{txt} 26{com}. rename dev_pre dev_precip
{txt} 27{com}. label var precip "Average monthly precip (mm)"
{txt} 28{com}. label var dev_precip "Precip anomaly"
{txt} 29{com}. {c )-} 
{txt} 30{com}. 
. 
. 
. drop if year<2000 | year>2011
{txt} 31{com}. 
. drop av`v'
{txt} 32{com}. 
. sort x y year
{txt} 33{com}. 
. save "../data/annual_av_`v'.dta", replace
{txt} 34{com}. {c )-}
{txt}(43,200 observations read)
(43,200 real changes made)
{res}{txt}{p 0 4 2}
file {bf}
C:\Users\hilar\AppData\Local\Temp\ST_70c8_000001.tmp{rm}
saved
as .dta format
{p_end}
(43,200 observations read)
(43,200 real changes made)
{res}{txt}{p 0 4 2}
file {bf}
C:\Users\hilar\AppData\Local\Temp\ST_70c8_000002.tmp{rm}
saved
as .dta format
{p_end}
(43,200 observations read)
(43,200 real changes made)
{res}{txt}{p 0 4 2}
file {bf}
C:\Users\hilar\AppData\Local\Temp\ST_70c8_000003.tmp{rm}
saved
as .dta format
{p_end}
(2,700 observations deleted)
(8,100 real changes made)
{res}{txt}(j = 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720)

Data{col 36}Wide{col 43}->{col 48}Long
{hline 77}
Number of observations     {res}       8,100   {txt}->   {res}5,832,000   
{txt}Number of variables        {res}         722   {txt}->   {res}4           
{txt}j variable (720 values)                   ->   {res}x
{txt}xij variables:
                   {res}tmp1 tmp2 ... tmp720   {txt}->   {res}tmp
{txt}{hline 77}
(1,924,256 real changes made)
(3,907,410 missing values generated)
(3,907,410 missing values generated)
(3,499,200 observations deleted)
{p 0 4 2}
file {bf}
../data/annual_av_tmp.dta{rm}
saved
{p_end}
(43,200 observations read)
(43,200 real changes made)
{res}{txt}{p 0 4 2}
file {bf}
C:\Users\hilar\AppData\Local\Temp\ST_70c8_000004.tmp{rm}
saved
as .dta format
{p_end}
(43,200 observations read)
(43,200 real changes made)
{res}{txt}{p 0 4 2}
file {bf}
C:\Users\hilar\AppData\Local\Temp\ST_70c8_000005.tmp{rm}
saved
as .dta format
{p_end}
(43,200 observations read)
(43,200 real changes made)
{res}{txt}{p 0 4 2}
file {bf}
C:\Users\hilar\AppData\Local\Temp\ST_70c8_000006.tmp{rm}
saved
as .dta format
{p_end}
(2,700 observations deleted)
(8,100 real changes made)
{res}{txt}(j = 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720)

Data{col 36}Wide{col 43}->{col 48}Long
{hline 77}
Number of observations     {res}       8,100   {txt}->   {res}5,832,000   
{txt}Number of variables        {res}         722   {txt}->   {res}4           
{txt}j variable (720 values)                   ->   {res}x
{txt}xij variables:
                   {res}pre1 pre2 ... pre720   {txt}->   {res}pre
{txt}{hline 77}
(1,924,469 real changes made)
(3,907,410 missing values generated)
(3,907,410 missing values generated)
{res}{txt}(3,499,200 observations deleted)
{p 0 4 2}
file {bf}
../data/annual_av_pre.dta{rm}
saved
{p_end}

{com}. 
. 
. 
. **# sc-PDSI
. clear
{txt}
{com}. infile pdsi1-pdsi720 using "../data/cru/scPDSI.1901.2016.dat"  in 427681/l
{txt}(73,440 observations read)

{com}. 
. * replace missing values with true missing
. quietly: mvdecode pdsi1-pdsi720, mv(-9999)
{txt}
{com}. 
. gen int y=mod((_n-1),360)
{txt}
{com}. gen int year=int((_n-1)/4320)
{txt}
{com}. gen int month=int((_n-1)/360)-year*12+1
{txt}
{com}. replace year=year+2000
{txt}(73,440 real changes made)

{com}. 
. *drop observations outside the range we use:
. drop if y<31 | y>300
{txt}(18,360 observations deleted)

{com}. 
. *renumber y to account for dropped polar rows
. replace y=y-30
{txt}(55,080 real changes made)

{com}. 
. tempfile pdsi
{txt}
{com}. save `pdsi'
{txt}{p 0 4 2}
file {bf}
C:\Users\hilar\AppData\Local\Temp\ST_70c8_000007.tmp{rm}
saved
as .dta format
{p_end}

{com}. 
. *create annual averages and mins
. forvalues i = 1(1)720 {c -(} 
{txt}  2{com}.     qui gen pdsi_min`i'=pdsi`i'
{txt}  3{com}.         qui gen pdsi_median`i'=pdsi`i'
{txt}  4{com}.     {c )-}
{txt}
{com}. 
. collapse (mean) pdsi1-pdsi720 (min) pdsi_min* (median) pdsi_median*, by(year y)
{res}{txt}
{com}.         
. reshape long pdsi pdsi_min pdsi_median, i(y year) j(x) favor(speed)
{res}{txt}(j = 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720)

Data{col 36}Wide{col 43}->{col 48}Long
{hline 77}
Number of observations     {res}       4,590   {txt}->   {res}3,304,800   
{txt}Number of variables        {res}       2,162   {txt}->   {res}6           
{txt}j variable (720 values)                   ->   {res}x
{txt}xij variables:
                {res}pdsi1 pdsi2 ... pdsi720   {txt}->   {res}pdsi
    pdsi_min1 pdsi_min2 ... pdsi_min720   {txt}->   {res}pdsi_min
pdsi_median1 pdsi_median2 ... pdsi_median720{txt}-> {res}pdsi_median
{txt}{hline 77}

{com}. 
. rename pdsi pdsi_av
{res}{txt}
{com}. 
. sort y x year
{txt}
{com}. 
. tempfile pdsi_annual
{txt}
{com}. save `pdsi_annual'
{txt}{p 0 4 2}
file {bf}
C:\Users\hilar\AppData\Local\Temp\ST_70c8_000008.tmp{rm}
saved
as .dta format
{p_end}

{com}. 
. use `pdsi', clear
{txt}
{com}. 
. keep if (month==6 & y<=150) | (month==12 & y>150)
{txt}(50,490 observations deleted)

{com}. 
. drop month
{txt}
{com}. 
. reshape long pdsi, i(y year) j(x) favor(speed)
{res}{txt}(j = 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720)

Data{col 36}Wide{col 43}->{col 48}Long
{hline 77}
Number of observations     {res}       4,590   {txt}->   {res}3,304,800   
{txt}Number of variables        {res}         722   {txt}->   {res}4           
{txt}j variable (720 values)                   ->   {res}x
{txt}xij variables:
                {res}pdsi1 pdsi2 ... pdsi720   {txt}->   {res}pdsi
{txt}{hline 77}

{com}. 
. rename pdsi pdsi_summer
{res}{txt}
{com}. 
. label var pdsi_summer "scPDSI in summer"
{txt}
{com}. 
. sort y x year
{txt}
{com}. 
. merge 1:1 y x year using `pdsi_annual', keep(match)
{res}
{txt}{col 5}Result{col 33}Number of obs
{col 5}{hline 41}
{col 5}Not matched{col 30}{res}               0
{txt}{col 5}Matched{col 30}{res}       3,304,800{txt}  (_merge==3)
{col 5}{hline 41}

{com}. drop _merge 
{txt}
{com}. 
. save "../data/pdsi.dta", replace
{txt}{p 0 4 2}
file {bf}
../data/pdsi.dta{rm}
saved
{p_end}

{com}.  
. timer off 1
{txt}
{com}. timer list 1
{res}   1:    448.03 /        1 =     448.0290
{txt}
{com}. 
. log close
      {txt}name:  {res}<unnamed>
       {txt}log:  {res}C:\Users\hilar\Box\lights_2022\replication package\code\read_ascii_cru.smcl
  {txt}log type:  {res}smcl
 {txt}closed on:  {res}13 Dec 2025, 11:50:26
{txt}{.-}
{smcl}
{txt}{sf}{ul off}